package cn.melonlib.cores.graphql.config.bean.impl;

import cn.melonlib.cores.graphql.config.bean.ParameterReader;
import cn.melonlib.cores.jpa.model.bean.collections.JsonMap;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class MapReader<V> implements ParameterReader<Map<String,V>> {
    @Override
    public JsonMap<V> read(String fieldName, DataFetchingEnvironment env, Class<Map<String,V>> cls) {
        Map<String,V> map=env.getArgument(fieldName);
        if(map==null){
            return null;
        }
        return JsonMap.createMap(map);
    }
}
